package com.ihr360.payroll.controller.salaryprofile;

import com.ihr360.authority.sharing.annonation.ControlMode;
import com.ihr360.authority.sharing.annonation.RestControl;
import com.ihr360.authority.sharing.privilege.AccessControlMethod;
import com.ihr360.commons.context.session.Ihr360SessionContextHolder;
import com.ihr360.commons.vo.ResultInfo;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.payroll.entity.staff.CompanySalaryProfileEntity;
import com.ihr360.payroll.model.dto.salary.profile.CompanySalaryProfile;
import com.ihr360.payroll.service.salaryprofile.CompanySalaryProfileService;
import com.ihr360.rest.service.SimpleRestService;
import com.ihr360.rest.webmvc.AbstractRestSimpleWithLongIdController;
import com.ihr360.shared.advice.response.DisableResponseAdvice;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/companySalaryProfiles")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.SALARY_CODE, mainModuleName = ModuleCodeStore.Module.SALARY_NAME, hasExtendsAbstractRestController = true,
        subModuleCode = ModuleCodeStore.Module.Salary.STAFF_PAY_ROLLINFO_CODE, subModuleName = ModuleCodeStore.Module.Salary.STAFF_PAY_ROLLINFO_NAME)
@RestControl(mode = ControlMode.DENY, controls = {AccessControlMethod.METHODS.deleteOne,
        AccessControlMethod.METHODS.batchDelete,
        AccessControlMethod.METHODS.getAll,
        AccessControlMethod.METHODS.getOne,
        AccessControlMethod.METHODS.update,
        AccessControlMethod.METHODS.create,
        AccessControlMethod.METHODS.getAllInCompany})
public class CompanySalaryProfileController extends AbstractRestSimpleWithLongIdController<CompanySalaryProfile> {

    @Autowired
    private CompanySalaryProfileService companySalaryProfileService;


    @Override
    public SimpleRestService<CompanySalaryProfile, Long> getSimpleRestService() {
        return companySalaryProfileService;
    }

    @ApiOperation(value = "添加公司薪资档案字段")
    @PostMapping(value = "/profileField/add/{code}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "添加公司薪资档案字段", functionCode = ModuleCodeStore.Function.EDIT)
    public Boolean addProfileField(@PathVariable(name = "code", required = true) String code) {
        return companySalaryProfileService.addProfileField(code);
    }

    @ApiOperation(value = "初始化公司薪资方案")
    @PostMapping(value = "/init", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "初始化公司薪资方案", functionCode = ModuleCodeStore.Function.EDIT, isPublic = true)
    public ResultInfo initCompanySalaryProfile(@RequestParam String companyId) {
        return companySalaryProfileService.initCompanySalaryProfile(companyId);
    }

    @ApiOperation(value = "批量初始化公司薪资方案")
    @GetMapping(value = "/init/batch", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "批量初始化公司薪资方案", functionCode = ModuleCodeStore.Function.EDIT, isPublic = true)
    public ResultInfo batchInitCompanySalaryProfile() {
        return companySalaryProfileService.batchInitCompanySalaryProfile();
    }

    @ApiOperation(value = "获取公司薪资档案信息,用于数据修复")
    @GetMapping(value = "/getByCompanyId", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "获取公司薪资档案信息,用于数据修复", functionCode = ModuleCodeStore.Function.VIEW, isPublic = true)
    @DisableResponseAdvice
    public CompanySalaryProfileEntity getByCompanyId(@RequestParam String companyId) {
        return companySalaryProfileService.getByCompanyId(companyId);
    }

    @ApiOperation(value = "获取公司薪资档案")
    @GetMapping(value = "/companyId", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "获取公司薪资档案", functionCode = ModuleCodeStore.Function.VIEW)
    public CompanySalaryProfileEntity getByCompanyId() {
        String companyId = Ihr360SessionContextHolder.getCompanyId();
        return companySalaryProfileService.getByCompanyId(companyId);
    }


}
